<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>DataExtractor: E:/cas/cas.0.7.0/sfw/src/MinConsole/MinConsole.0.8.0/MinConsole/Gaf/Utils/Log/Logger.cs Source File</title>
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<link href="../../doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.7.2 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul class="tablist">
      <li><a href="../../index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="../../namespaces.html"><span>Packages</span></a></li>
      <li><a href="../../annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="../../files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div class="tabs2">
    <ul class="tablist">
      <li><a href="../../files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<h1>E:/cas/cas.0.7.0/sfw/src/MinConsole/MinConsole.0.8.0/MinConsole/Gaf/Utils/Log/Logger.cs</h1>  </div>
</div>
<div class="contents">
<a href="../../d7/d7a/Logger_8cs.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 ﻿using System;
<a name="l00002"></a>00002 <span class="keyword">using</span> System.Text.RegularExpressions;
<a name="l00003"></a>00003 <span class="keyword">using</span> System.Data;
<a name="l00004"></a>00004 <span class="keyword">using</span> System.Diagnostics;
<a name="l00005"></a>00005 <span class="keyword">using</span> System.Collections.Specialized;
<a name="l00006"></a>00006 <span class="keyword">using</span> System.Text;
<a name="l00007"></a>00007 <span class="keyword">using</span> System.Resources; 
<a name="l00008"></a>00008 
<a name="l00009"></a><a class="code" href="../../dd/d31/namespaceMinConsole_1_1Gaf_1_1Utils_1_1Log.html">00009</a> <span class="keyword">namespace </span>MinConsole.Gaf.Utils.Log
<a name="l00010"></a>00010 {
<a name="l00011"></a><a class="code" href="../../d3/d03/classMinConsole_1_1Gaf_1_1Utils_1_1Log_1_1Logger.html">00011</a>     <span class="keyword">class </span><a class="code" href="../../d3/d03/classMinConsole_1_1Gaf_1_1Utils_1_1Log_1_1Logger.html">Logger</a>
<a name="l00012"></a>00012     {
<a name="l00013"></a>00013 
<a name="l00018"></a><a class="code" href="../../d3/d03/classMinConsole_1_1Gaf_1_1Utils_1_1Log_1_1Logger.html#ab4b0884e386293f353e5b145cacc11ed">00018</a>         <span class="keyword">public</span> <span class="keyword">static</span> <span class="keywordtype">void</span> Log(<span class="keywordtype">string</span> msg)
<a name="l00019"></a>00019         {
<a name="l00020"></a>00020 <span class="preprocessor">            #region Try </span>
<a name="l00021"></a>00021 <span class="preprocessor"></span>            <span class="keywordflow">try</span>
<a name="l00022"></a>00022             {
<a name="l00023"></a>00023             
<a name="l00024"></a>00024                 <span class="comment">//if have to log to the console log</span>
<a name="l00025"></a>00025                 <span class="keywordflow">if</span> (MinConsole.Conf.AppInstSettings.Instance.LogToConsole == <span class="keyword">true</span>)
<a name="l00026"></a>00026                 {
<a name="l00027"></a>00027                     MinConsole.Gaf.Utils.<a class="code" href="../../d3/d03/classMinConsole_1_1Gaf_1_1Utils_1_1Log_1_1Logger.html#ab4b0884e386293f353e5b145cacc11ed" title="Logs a message to the predifiend in the app settings logdir.">Log</a>.Logger.LogToConsole(msg);
<a name="l00028"></a>00028                 } <span class="comment">//eof if</span>
<a name="l00029"></a>00029 
<a name="l00030"></a>00030 
<a name="l00031"></a>00031                 <span class="comment">//if have to log to a file log</span>
<a name="l00032"></a>00032                 <span class="keywordflow">if</span> (MinConsole.Conf.AppInstSettings.Instance.LogToFile == <span class="keyword">true</span>)
<a name="l00033"></a>00033                 {
<a name="l00034"></a>00034                     MinConsole.Gaf.Utils.Log.Logger.DebugToFile(msg);
<a name="l00035"></a>00035                     MinConsole.Gaf.Utils.Log.Logger.LogToFile(msg);
<a name="l00036"></a>00036                 }
<a name="l00037"></a>00037             
<a name="l00038"></a>00038             } <span class="comment">//eof try </span>
<a name="l00039"></a>00039 <span class="preprocessor">            #endregion Try </span>
<a name="l00040"></a>00040 <span class="preprocessor"></span>
<a name="l00041"></a>00041 <span class="preprocessor">            #region Catch </span>
<a name="l00042"></a>00042 <span class="preprocessor"></span>
<a name="l00043"></a>00043             <span class="keywordflow">catch</span> (Exception ex)
<a name="l00044"></a>00044             {
<a name="l00045"></a>00045                 Console.WriteLine(<span class="stringliteral">&quot;Failed to log msg:&quot;</span> + msg.ToString());
<a name="l00046"></a>00046                 Console.WriteLine(<span class="stringliteral">&quot;Gaf.Utils.Log.Logger.Debug catch&quot;</span> + ex.Message.ToString());
<a name="l00047"></a>00047             } <span class="comment">//eof catch </span>
<a name="l00048"></a>00048             
<a name="l00049"></a>00049 <span class="preprocessor">            #endregion Catch</span>
<a name="l00050"></a>00050 <span class="preprocessor"></span>
<a name="l00051"></a>00051         } <span class="comment">//eof method </span>
<a name="l00052"></a>00052 
<a name="l00057"></a><a class="code" href="../../d3/d03/classMinConsole_1_1Gaf_1_1Utils_1_1Log_1_1Logger.html#a2b56966a86c04468bba9b157be9998b5">00057</a>         <span class="keyword">public</span> <span class="keyword">static</span> <span class="keywordtype">void</span> LogToFile(<span class="keywordtype">string</span> msg)
<a name="l00058"></a>00058         {
<a name="l00059"></a>00059             <span class="comment">//get the LogDir from the settings file</span>
<a name="l00060"></a>00060             String strLogDir = String.Empty;
<a name="l00061"></a>00061             strLogDir = MinConsole.Conf.AppInstSettings.Instance.LogDir; 
<a name="l00062"></a>00062             
<a name="l00063"></a>00063             <span class="comment">//add the \ at the end if it is not added </span>
<a name="l00064"></a>00064             <span class="keywordflow">if</span>(strLogDir.EndsWith(<span class="stringliteral">@&quot;\&quot;</span>) == <span class="keyword">false</span>)
<a name="l00065"></a>00065                 strLogDir = strLogDir + <span class="stringliteral">@&quot;\&quot;</span>;
<a name="l00066"></a>00066 
<a name="l00067"></a>00067             <span class="keywordflow">try</span>
<a name="l00068"></a>00068             {
<a name="l00069"></a>00069                 <span class="comment">//create the dir if it does not exist </span>
<a name="l00070"></a>00070                 <span class="keywordflow">if</span> (System.IO.Directory.Exists(strLogDir) == <span class="keyword">false</span>)
<a name="l00071"></a>00071                     System.IO.Directory.CreateDirectory(strLogDir);
<a name="l00072"></a>00072             }
<a name="l00073"></a>00073             <span class="keywordflow">catch</span> (Exception ex)
<a name="l00074"></a>00074             {
<a name="l00075"></a>00075                 Console.WriteLine(<span class="stringliteral">&quot;The log directory &quot;</span> + strLogDir + <span class="stringliteral">&quot; cannot be created &quot;</span> + ex.Message);
<a name="l00076"></a>00076                 <span class="keywordflow">return</span>;
<a name="l00077"></a>00077             }
<a name="l00078"></a>00078             <span class="comment">//build the LogFileName from the settings file</span>
<a name="l00079"></a>00079             String strLogFile = String.Empty;
<a name="l00080"></a>00080             msg = DateTime.Now.ToString(MinConsole.Conf.AppInstSettings.Instance.LogMessageSuffix) + <span class="stringliteral">&quot; &quot;</span> + msg;
<a name="l00081"></a>00081             
<a name="l00082"></a>00082                 <span class="comment">//todo: add generic file log name according to the application name ...</span>
<a name="l00083"></a>00083                 strLogFile = strLogDir + DateTime.Now.ToString(
<a name="l00084"></a>00084                 MinConsole.Conf.AppInstSettings.Instance.LogFileNameTimePattern.ToString()) + <span class="stringliteral">&quot;.&quot;</span> + 
<a name="l00085"></a>00085                 MinConsole.Conf.AppInstSettings.Instance.LogFileNameSuffix.ToString();
<a name="l00086"></a>00086 
<a name="l00087"></a>00087                MinConsole.Gaf.IO.FileUtility.AppendToFile(strLogFile, msg);
<a name="l00088"></a>00088 
<a name="l00089"></a>00089         } <span class="comment">//eof method </span>
<a name="l00090"></a>00090 
<a name="l00095"></a><a class="code" href="../../d3/d03/classMinConsole_1_1Gaf_1_1Utils_1_1Log_1_1Logger.html#a270ffa9f02a6ffbad7da84727d4c967c">00095</a>         <span class="keyword">public</span> <span class="keyword">static</span> <span class="keywordtype">void</span> LogToConsole(<span class="keywordtype">string</span> msg)
<a name="l00096"></a>00096         {
<a name="l00097"></a>00097             msg = DateTime.Now.ToString(MinConsole.Conf.AppInstSettings.Instance.LogMessageSuffix) + <span class="stringliteral">&quot; &quot;</span> + msg;
<a name="l00098"></a>00098             Console.WriteLine(msg); 
<a name="l00099"></a>00099         } <span class="comment">//eof method </span>
<a name="l00100"></a>00100 
<a name="l00105"></a><a class="code" href="../../d3/d03/classMinConsole_1_1Gaf_1_1Utils_1_1Log_1_1Logger.html#ad1db02d4c4b412c54b352d1e541e8016">00105</a>         <span class="keyword">public</span> <span class="keyword">static</span> <span class="keywordtype">void</span> LogErrorToConsole(<span class="keywordtype">string</span> msg)
<a name="l00106"></a>00106         {
<a name="l00107"></a>00107             msg = DateTime.Now.ToString(MinConsole.Conf.AppInstSettings.Instance.LogMessageSuffix) + <span class="stringliteral">&quot; &quot;</span> + msg;
<a name="l00108"></a>00108             Console.Error.WriteLine(msg);
<a name="l00109"></a>00109         } <span class="comment">//eof method </span>
<a name="l00110"></a>00110 
<a name="l00111"></a>00111 
<a name="l00116"></a><a class="code" href="../../d3/d03/classMinConsole_1_1Gaf_1_1Utils_1_1Log_1_1Logger.html#a5c10f1454b60f5feeba5b75251f291d3">00116</a>         <span class="keyword">public</span> <span class="keyword">static</span> <span class="keywordtype">void</span> Debug(<span class="keywordtype">string</span> msg)
<a name="l00117"></a>00117         {
<a name="l00118"></a>00118 <span class="preprocessor">            #region Try</span>
<a name="l00119"></a>00119 <span class="preprocessor"></span>            <span class="keywordflow">try</span>
<a name="l00120"></a>00120             {
<a name="l00121"></a>00121 
<a name="l00122"></a>00122                 <span class="comment">//if have to log to the console log</span>
<a name="l00123"></a>00123                 <span class="keywordflow">if</span> (MinConsole.Conf.AppInstSettings.Instance.LogToConsole == <span class="keyword">true</span>)
<a name="l00124"></a>00124                 {
<a name="l00125"></a>00125                     MinConsole.Gaf.Utils.Log.Logger.DebugToConsole(msg);
<a name="l00126"></a>00126                 } <span class="comment">//eof if</span>
<a name="l00127"></a>00127 
<a name="l00128"></a>00128 
<a name="l00129"></a>00129                 <span class="comment">//if have to log to a file log</span>
<a name="l00130"></a>00130                 <span class="keywordflow">if</span> (MinConsole.Conf.AppInstSettings.Instance.LogToFile == <span class="keyword">true</span>)
<a name="l00131"></a>00131                 {
<a name="l00132"></a>00132                     MinConsole.Gaf.Utils.Log.Logger.DebugToFile(msg);
<a name="l00133"></a>00133                 }
<a name="l00134"></a>00134 
<a name="l00135"></a>00135 
<a name="l00136"></a>00136             } <span class="comment">//eof try </span>
<a name="l00137"></a>00137 <span class="preprocessor">            #endregion Try</span>
<a name="l00138"></a>00138 <span class="preprocessor"></span>                
<a name="l00139"></a>00139 <span class="preprocessor">            #region Catch</span>
<a name="l00140"></a>00140 <span class="preprocessor"></span>
<a name="l00141"></a>00141             <span class="keywordflow">catch</span> (Exception ex)
<a name="l00142"></a>00142             {
<a name="l00143"></a>00143                 Console.Error.WriteLine(<span class="stringliteral">&quot;Failed to log msg:&quot;</span> + msg.ToString());
<a name="l00144"></a>00144                 Console.Error.WriteLine(<span class="stringliteral">&quot;Gaf.Utils.Log.Logger.Debug catch&quot;</span> + ex.Message.ToString());
<a name="l00145"></a>00145             } <span class="comment">//eof catch </span>
<a name="l00146"></a>00146 
<a name="l00147"></a>00147 <span class="preprocessor">            #endregion Catch</span>
<a name="l00148"></a>00148 <span class="preprocessor"></span>
<a name="l00149"></a>00149         } <span class="comment">//eof method </span>
<a name="l00150"></a>00150 
<a name="l00155"></a><a class="code" href="../../d3/d03/classMinConsole_1_1Gaf_1_1Utils_1_1Log_1_1Logger.html#a3c89e1d5d4ddf2df60afe018d77f7f06">00155</a>         <span class="keyword">public</span> <span class="keyword">static</span> <span class="keywordtype">void</span> DebugToFile(<span class="keywordtype">string</span> msg)
<a name="l00156"></a>00156         {
<a name="l00157"></a>00157             <span class="comment">//get the LogDir from the settings file</span>
<a name="l00158"></a>00158             String strLogDir = String.Empty;
<a name="l00159"></a>00159             strLogDir = MinConsole.Conf.AppInstSettings.Instance.LogDir;
<a name="l00160"></a>00160 
<a name="l00161"></a>00161             <span class="comment">//add the \ at the end if it is not added </span>
<a name="l00162"></a>00162             <span class="keywordflow">if</span> (strLogDir.EndsWith(<span class="stringliteral">@&quot;\&quot;</span>) == <span class="keyword">false</span>)
<a name="l00163"></a>00163                 strLogDir = strLogDir + <span class="stringliteral">@&quot;\&quot;</span>;
<a name="l00164"></a>00164 
<a name="l00165"></a>00165             <span class="keywordflow">try</span>
<a name="l00166"></a>00166             {
<a name="l00167"></a>00167                 <span class="comment">//create the dir if it does not exist </span>
<a name="l00168"></a>00168                 <span class="keywordflow">if</span> (System.IO.Directory.Exists(strLogDir) == <span class="keyword">false</span>)
<a name="l00169"></a>00169                     System.IO.Directory.CreateDirectory(strLogDir);
<a name="l00170"></a>00170             }
<a name="l00171"></a>00171             <span class="keywordflow">catch</span> (Exception ex)
<a name="l00172"></a>00172             {
<a name="l00173"></a>00173                 Console.Error.WriteLine(<span class="stringliteral">&quot;The log directory &quot;</span> + strLogDir + <span class="stringliteral">&quot; cannot be created &quot;</span> + ex.Message);
<a name="l00174"></a>00174                 <span class="keywordflow">return</span>;
<a name="l00175"></a>00175             }
<a name="l00176"></a>00176             <span class="comment">//build the LogFileName from the settings file</span>
<a name="l00177"></a>00177             String strDebugFile = String.Empty;
<a name="l00178"></a>00178             msg = DateTime.Now.ToString(MinConsole.Conf.AppInstSettings.Instance.LogMessageSuffix) + <span class="stringliteral">&quot; &quot;</span>  + msg;
<a name="l00179"></a>00179 
<a name="l00180"></a>00180             <span class="comment">//todo: add generic file log name according to the application name ...</span>
<a name="l00181"></a>00181             strDebugFile = strLogDir + DateTime.Now.ToString(
<a name="l00182"></a>00182             MinConsole.Conf.AppInstSettings.Instance.LogFileNameTimePattern.ToString()) + <span class="stringliteral">&quot;.&quot;</span> +
<a name="l00183"></a>00183             MinConsole.Conf.AppInstSettings.Instance.DebugFileNameSuffix.ToString();
<a name="l00184"></a>00184 
<a name="l00185"></a>00185             MinConsole.Gaf.IO.FileUtility.AppendToFile(strDebugFile, msg);
<a name="l00186"></a>00186 
<a name="l00187"></a>00187         } <span class="comment">//eof method </span>
<a name="l00188"></a>00188 
<a name="l00193"></a><a class="code" href="../../d3/d03/classMinConsole_1_1Gaf_1_1Utils_1_1Log_1_1Logger.html#af1fff6edf995ae4436fc743f3b002f5d">00193</a>         <span class="keyword">public</span> <span class="keyword">static</span> <span class="keywordtype">void</span> DebugToConsole(<span class="keywordtype">string</span> msg)
<a name="l00194"></a>00194         {
<a name="l00195"></a>00195             msg = DateTime.Now.ToString(MinConsole.Conf.AppInstSettings.Instance.LogMessageSuffix) + <span class="stringliteral">&quot; &quot;</span>  + msg;
<a name="l00196"></a>00196             Console.WriteLine(msg);
<a name="l00197"></a>00197         } <span class="comment">//eof method </span>
<a name="l00198"></a>00198         
<a name="l00199"></a>00199 
<a name="l00200"></a>00200 
<a name="l00201"></a>00201 
<a name="l00202"></a>00202 
<a name="l00203"></a>00203 
<a name="l00204"></a>00204 
<a name="l00205"></a>00205     } <span class="comment">//eof class </span>
<a name="l00206"></a>00206 <span class="comment">//eof class</span>
<a name="l00207"></a>00207 } <span class="comment">//eof namespace </span>
</pre></div></div>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Sat Jan 22 2011 22:24:47 for DataExtractor by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="../../doxygen.png" alt="doxygen"/></a> 1.7.2 </small></address>
</body>
</html>
